<?php
/* @var $this AttendanceController */
/* @var $model Attendance */

$this->breadcrumbs=array(
	'Attendances'=>array('index'),
	$model->groupname,
);

$this->menu=array(
	array('label'=>'List Attendance', 'url'=>array('index')),
	array('label'=>'Create Attendance', 'url'=>array('create')),
	array('label'=>'Update Attendance', 'url'=>array('update', 'id'=>$model->id)),
	array('label'=>'Delete Attendance', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
	array('label'=>'Manage Attendance', 'url'=>array('admin')),
);
?>

<h1>View Attendance #<?php echo $model->groupname; ?></h1>
<?php echo CHtml::link('Create Attendance', '#/', array('onclick'=>'$("#my-dialog").dialog("open"); return false;')); ?>

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'attendance-form1',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>
<table>
<tr>
	<td width="100%" height="1%"><?php if($students != null)echo "Name/Surname"; ?></td>
    <?php //$titles; ?>
    <?php if($dates != null): ?>
    <?php foreach($dates as $date): ?>
    <td style="-moz-transform:rotate(270deg); -o-transform:rotate(270deg); -webkit-transform:rotate(270deg)" width="1%" height="100%"><?php echo $date ; ?></td>
    <?php endforeach; ?>
    <?php endif; ?>
</tr>
<?php if($students != null): ?><?php $hasAttendance = false; ?>
<?php foreach($students as $st): ?>
		<tr>
        <td><?php echo $st->first_name . " " . $st->last_name; ?></td>
        <?php if(Attendance::model()->findAllByAttributes(array('users_id'=>$st->users_id)) != null): ?>
        <?php $hasAttendance=true; ?>
		<?php foreach(Attendance::model()->findAllByAttributes(array('users_id'=>$st->users_id)) as $g0): ?>
        	<td>
            <?php $_id = $g0->id_not_needed; ?>
            <?php echo $form->textField($model2, "[$_id]attendance", array('value'=>Attendance::model()->findByPk($g0->id_not_needed)->attendance, 'size'=>2)); ?>
            </td>
        <?php endforeach; ?><?php endif; ?>
        </tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<div class="row buttons">
		<?php if($students != null && $hasAttendance == true): ?>
		<?php echo CHtml::submitButton($model2->isNewRecord ? 'Save' : 'Save'); ?>
        <?php endif;?>
</div>			

<?php $this->endWidget(); ?>
</div><!-- form -->
<div>
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
	'id'=>'my-dialog',
	'options'=>array(
		'title'=>'Create Grade',
		'width'=>500,
		'height'=>300,
		'autoOpen'=>false,
	),
)); 
	$new_attendance = new Attendance;
	
	$form1 = $this->beginWidget('CActiveForm', array(
		'id'=>'quick-form',
		'enableClientValidation'=>true,
		'clientOptions'=>array(
			'validateOnSubmit'=>true,
		),
		'action'=>array('attendance/createattendance'),
	));
	
	echo "<div class='row'>";
	echo "Date: " . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	echo $form1->textField($new_attendance, 'DateCreated', array('value'=>date_create()->format('Y-m-d'))) . "<br/>";
	echo "</div><div class='row'><br/> Group: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	echo $form1->textField($new_attendance, 'attendance', array('value'=>$model->id, 'readonly'=>true, 'size'=>1)) . "</div><br/><div class='row'>";
	//echo "Choose type: ";
	//echo $form1->dropDownList($new_attendance, 'type', CHtml::listData(GradingStandard::model()->findAll(), 'id', 'type'), array('class'=>'my-drop-down', 'options'=>array('1'=>array('selected'=>"selected"))));
	echo "</div><br/><br/><br/>";
	
		echo CHtml::submitButton($new_attendance->isNewRecord ? 'Create' : 'Create');
	
	
	$this->endWidget();
 $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
</div>
